// pages/opt_user_admin/opt_page/produce_list/produce_list.js
var app = getApp()
const util = require('../../../../../utils/util.js')

//常量数据配置
var ConstantData = require('../../../../../common/constant_data.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    // testInfo_new:[],
    // pageNum:1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getNowDate();
    this.getTestData();
    // this.getTodayData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  
  toDetail:function(e){
    let dateType = e.currentTarget.dataset.dateType;
    let startTime = e.currentTarget.dataset.startTime;
    let endTime = e.currentTarget.dataset.endTime;
    wx.navigateTo({
      url: './testDetailList/testDetailList?dateType='+dateType+'&startTime='+startTime+'&endTime='+endTime,
    })
  },

  getTestData:function(){
    console.log('getTestData');
    let that = this;
    app.executeRequest(function (header) {
      wx.request({
        url: ConstantData.CONSTATNT_DATA.BASE_URL + '/lease_admin/produce_list/produce_test_info',
        header: header,
        data:{
          startTime:that.data.startTime,
          endTime:that.data.endTime,
        },
        success: function (res) {
          if (res.data.result === 0 && res.data.data) {
            that.setData({
              testDetailInfo:res.data.data.testDetailInfo,
              testDateCountInfoList:res.data.data.testDateCountInfoList,
            })
          }
        }
      })
    });
  },
  getTodayData:function() {
    console.log('getTodayData');
    let that = this;
    app.executeRequest(function (header) {
      wx.request({
        url: ConstantData.CONSTATNT_DATA.BASE_URL + '/lease_admin/produce_list/produce_test_info',
        header: header,
        data:{
          startTime:that.data.endTime,
          endTime:that.data.endTime,
        },
        success: function (res) {
          if (res.data.result === 0 && res.data.data) {
            that.setData({
              testInfo_new_today:res.data.data.newTestPileCount[0],
              testInfo_old_today:res.data.data.oldTestPileCount[0],
            })
          }
        }
      })
    });
  },
  startTimeChange(e){
    this.setData({
      startTime: e.detail.value
    })
    this.data.testInfo_new={}
    this.data.testInfo_old={}
    this.getTestData();
  },
  endTimeChange(e) {
    this.setData({
      endTime: e.detail.value
    })
    this.data.testInfo_new = {}
    this.data.testInfo_old = {}
    this.getTestData()
  },
  getNowDate: function () {
    let reg = /\//g
    let nowTime = new Date()
    let agoTime = new Date(nowTime.getTime()-1000*60*60*24*7)
    let nowDate = util.formatTime(nowTime).substr(0, 10).replace(reg, '-')
    let agoDate = util.formatTime(agoTime).substr(0, 10).replace(reg, '-')
    this.setData({
      date:nowDate,
      endTime: nowDate,
      startTime: agoDate,
    })
  },

})